package com.mudalov.rec.dao.factory;

import com.mudalov.rec.dao.hibernate.impl.HbnAdminDAO;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.mudalov.rec.dao.hibernate.impl.HbnMaterialDAO;
import com.mudalov.rec.dao.hibernate.impl.HbnQuestionDAO;
import com.mudalov.rec.dao.hibernate.impl.HbnRoleDAO;
import com.mudalov.rec.dao.hibernate.impl.HbnStudentDAO;
import com.mudalov.rec.dao.hibernate.impl.HbnStudyProgramDAO;
import com.mudalov.rec.dao.hibernate.impl.HbnSubjectDAO;
import com.mudalov.rec.dao.hibernate.impl.HbnTeacherDAO;
import com.mudalov.rec.dao.hibernate.impl.HbnTestDAO;
import com.mudalov.rec.dao.hibernate.impl.HbnTestResultDAO;
import com.mudalov.rec.dao.hibernate.util.RecHbnDbInitializer;
import com.mudalov.rec.dao.interfaces.IAdminDAO;
import com.mudalov.rec.dao.interfaces.IDbInitializer;
import com.mudalov.rec.dao.interfaces.IMaterialDAO;
import com.mudalov.rec.dao.interfaces.IQuestionDAO;
import com.mudalov.rec.dao.interfaces.IRoleDAO;
import com.mudalov.rec.dao.interfaces.IStudentDAO;
import com.mudalov.rec.dao.interfaces.IStudyProgramDAO;
import com.mudalov.rec.dao.interfaces.ISubjectDAO;
import com.mudalov.rec.dao.interfaces.ITeacherDAO;
import com.mudalov.rec.dao.interfaces.ITestDAO;
import com.mudalov.rec.dao.interfaces.ITestResultDAO;

public abstract class HbnDAOFactory extends DAOFactory {

	private SessionFactory sessionFactory;

	private Configuration configuration;

	protected HbnDAOFactory() {
		configuration = new Configuration().configure(getConfigurationFile());
		sessionFactory = configuration.buildSessionFactory();
	}

	public abstract String getConfigurationFile();

	public Configuration getConfiguration() {
		return configuration;
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void shutdown() {
		sessionFactory.close();
	}

	public void buildSessionFactory() {
		sessionFactory = configuration.buildSessionFactory();
	}
	

	@Override
	public IMaterialDAO getMaterialDAO() {
		return (IMaterialDAO)new HbnMaterialDAO(sessionFactory);
	}

	@Override
	public IQuestionDAO getQuestionDAO() {
		return new HbnQuestionDAO(sessionFactory);
	}

	@Override
	public IStudyProgramDAO getStudyProgramDAO() {
		return new HbnStudyProgramDAO(sessionFactory);
	}

	@Override
	public ISubjectDAO getSubjectDAO() {
		return new HbnSubjectDAO(sessionFactory);
	}

	@Override
	public ITestDAO getTestDAO() {
		return new HbnTestDAO(sessionFactory);
	}

	@Override
	public ITestResultDAO getTestResultDAO() {
		return new HbnTestResultDAO(sessionFactory);
	}
	
	@Override
	public IDbInitializer getDbInitializer() {
		return new RecHbnDbInitializer(sessionFactory, configuration);
	}

    @Override
	public IRoleDAO getRoleDAO() {
		return new HbnRoleDAO(sessionFactory);
	}

    @Override
	public IStudentDAO getStudentDAO() {
		return new HbnStudentDAO(sessionFactory);
	}

    @Override
	public IAdminDAO getAdminDAO() {
		return new HbnAdminDAO(sessionFactory);
	}

    @Override
	public ITeacherDAO getTeacherDAO() {
		return new HbnTeacherDAO(sessionFactory);
	}
}
